<template>
  <a-modal
    :title="title"
    :width="modalWidth"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    :destroyOnClose="destoryClose"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-card :bordered="false">

      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
      </div>
      <!-- 操作按钮区域 -->
      <!-- table区域-begin -->
      <div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{selectedRowKeys.length }}</a>项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>


        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type: rowSelectType}"
          @change="handleTableChange"
          :customRow="rowFun"
        >
          <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
        </span>
        </a-table>
      </div>
      <mms-in-storage-dialog-modal  ref="modalForm" @ok="modalFormOk"></mms-in-storage-dialog-modal>
    </a-card>
  </a-modal>
</template>

<script>
  import { JeecgListMixin } from '@lone/lone-vue/src/mixins/JeecgListMixin'
  import { getAction} from '@lone/lone-vue/src/api/manage'
  import MmsInStorageDialogModal from './MmsInStorageDialogModal'

  export default {
    name: "MmsInStorageModal",
    mixins: [JeecgListMixin],
    components: {
      MmsInStorageDialogModal
    },
    data () {
      return {
        title:"待接收明细",
        dataSource:[],
        destoryClose:true,
        num:'',
        //下标
        index:-1,
        visible: false,
        modalWidth:800,
        confirmLoading: false,
        rowSelectType:'checkbox',
        description: '待接收明细',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'物资编码',
            align:"center",
            dataIndex: 'materialCode'
          },
          {
            title:'物资名称',
            align:"center",
            dataIndex: 'materialName'
          },
          {
            title:'规格',
            align:"center",
            dataIndex: 'specs'
          },
          {
            title:'型号',
            align:"center",
            dataIndex: 'model'
          },
          {
            title:'计量单位',
            align:"center",
            dataIndex: 'unit'
          },
          {
            title:'到货数量',
            align:"center",
            dataIndex: 'qualifiedNum'
          },
          {
            title:'入库数量',
            align:"center",
            dataIndex: 'inNum'
          },
          {
            title:'仓库',
            align:"center",
            dataIndex: 'warehouseCode'
          },
          {
            title:'库位',
            align:"center",
            dataIndex: 'warehouse'
          },{
            title: '操作',
            dataIndex: 'id',
            scopedSlots: { customRender: 'action' },
          }],
        url: {
          list: '/cg/mmsWzPurchaseReceive/receivePageList'
        }
      }
    },
    created () {
    },
    methods: {
      handleEdit: function (record, params) {
        this.$refs.modalForm.edit(record, params);
        this.$refs.modalForm.title = "编辑";
        this.$refs.modalForm.disableSubmit = false;
      },
      showInfo(qualityId, num,selectedRowKeys){
        this.queryParam.qualityId = qualityId;
        this.num = num
        if(selectedRowKeys  !=''){
          this.selectedRowKeys = []
          this.selectedRowKeys.push(selectedRowKeys)
        }
        this.loadData(1);
        this.visible = true
      },
      handleOk(){
        if(this.index>=0){
          this.$emit("ok",this.selectionRows,this.index);
        }else{
          this.$emit("ok",this.selectionRows,this.num);
        }
        this.handleCancel();
      },
      modalFormOk(record) {
        let that = this;
        if (record && record.id) {
          const newData = [...this.dataSource];
          const target = newData.filter(item => item.id === record.id)[0];
          newData[newData.indexOf(target)] = record;
          this.dataSource = newData;
        }else{
          record['id'] = '';
          this.dataSource.push(record);
        }
      },
      handleCancel () {
        this.close()
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.index = 0
      },
      rowFun (record, index) {
        return {
          on: {
            dblclick: () => {
              this.$emit("ok",record,this.index)
              this.close()
            }
          }
        }
      }
    }
  }
</script>

<style lang="less" scoped>

</style>